home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 008 / sounder.arc / SOUNDER.ASM next >
Encoding:
Assembly Source File  |  1985-10-05  |  6.4 KB  |  361 lines

  1.  
  2. soundseg    segment public 'code'
  3.  
  4. main     proc far
  5.  
  6.     assume cs:soundseg
  7.  
  8.     org 100h
  9. start:
  10.  
  11.     jmp where_its_at
  12.  
  13. ;-------------------------------------------------------------------------
  14. ;        strings
  15. ;-------------------------------------------------------------------------
  16.  
  17. instructions    db    13,10 dup (10),'Sounder by MicroHelp (404) 973-9272',13,10,10
  18.     db    'Press ^C or Ctrl-Break to stop this program',13,10,10
  19.     db    'Duration = How long to play the note before putting in a delay',13,10,10
  20.     db    'Delay    = How long to pause between sounds',13,10,10
  21.     db    'Magnitude= How fast to change the duration and the delay',13,10,10,10
  22.     db      '  ',24,' = Higher tone                     ',25,' = Lower tone      ',13,10
  23.         db      '--> = Longer duration               <-- = Shorter duration',13,10
  24.     db    '  + = Longer delay between clicks     - = Shorter delay',13,10
  25.     db    '  I = Increase magnitude of changes   D = Decrease magnitude'
  26.     db    13,10,10
  27.     db    'Tone: 00040  Duration: 10000  Delay: 10000  Magnitude: 01024$'
  28. ; for cursor posit     ^7               ^24           ^38               ^56
  29.  
  30. ;-------------------------------------------------------------------------
  31. ;        values
  32. ;-------------------------------------------------------------------------
  33.  
  34. tone        db    40,0        ;extra bytes/words for overflow
  35. duration    dw    10000,0
  36. delay        dw    10000,0
  37. magnitude    dw    1024,0
  38. divisor        dw    256,0
  39.  
  40. ;-------------------------------------------------------------------------
  41. ;        procedures
  42. ;-------------------------------------------------------------------------
  43.  
  44. print_a_character    proc    near
  45.  
  46.     mov dl,'0'    
  47.  
  48. keep_trying:
  49.  
  50.     cmp ax,cx
  51.     jb  too_far
  52.     sub ax,cx        ;down by whatever we're looking at
  53.     inc dl
  54.     jmp keep_trying
  55.  
  56. too_far:
  57.  
  58.     push ax            ;save the value
  59.     mov ah,2
  60.     int 21h            ;print the character
  61.     pop ax            ;restore it
  62.     ret
  63.  
  64. print_a_character    endp
  65.     
  66. ;-------------------------------------------------------------------------
  67.  
  68. print_zero    proc    near
  69.  
  70.     push ax            ;save the value
  71.     mov dl,'0'
  72.     mov ah,2
  73.     int 21h
  74.     pop ax
  75.     ret
  76.  
  77. print_zero    endp
  78.  
  79. ;-------------------------------------------------------------------------
  80.  
  81. speaker    proc near
  82.  
  83.     mov al,182
  84.     out 43h,al        ; setup for sound
  85.     mov al,0
  86.     out 42h,al        ; low part
  87.  
  88.     mov al,tone
  89.  
  90.     out 42h,al        ; high part
  91.     in al,61h
  92.     push ax         ; save port value
  93.     or al,3
  94.     out 61h,al        ; turn speaker on
  95.  
  96.     mov cx,duration
  97.  
  98. p125:    loop p125        ; wait around
  99.     pop ax            ; restore original port value
  100.     out 61h,al        ; turn speaker off
  101.     ret 
  102.  
  103. speaker    endp
  104.  
  105. ;-------------------------------------------------------------------------
  106.  
  107. do_delay proc near
  108.  
  109.     mov cx,delay
  110.  
  111. delayloop:
  112.  
  113.     loop delayloop
  114.     ret 
  115.  
  116. do_delay     endp
  117.  
  118. ;-------------------------------------------------------------------------
  119.  
  120. cursor     proc    near
  121.  
  122. ;dl has column
  123.  
  124.     dec dl            ;subtract one for bios
  125.     mov dh,24        ;25th row
  126.     xor bh,bh
  127.     mov ah,2
  128.     int 10h
  129.     ret
  130.  
  131. cursor    endp
  132.  
  133. ;-------------------------------------------------------------------------
  134. ;              End of procedures - this is main program
  135. ;-------------------------------------------------------------------------
  136.  
  137. where_its_at:
  138.  
  139.     mov dx,offset instructions    ;print instructions
  140.     mov ah,9
  141.     int 21h
  142.  
  143.  
  144. is_key_waiting:
  145.  
  146.     mov ah,0bh
  147.     int 21h
  148.     cmp al,0ffh        ;has a key been pressed?
  149.     jz  get_the_key
  150.     jmp do_it            ;if not, go make some noise
  151.  
  152. get_the_key:
  153.  
  154.     mov ah,8        ;go get the key
  155.     int 21h            
  156.     cmp al,0        ;is it an extended key?
  157.     jz extended_code    ;if so, go to that area
  158.  
  159.     cmp al,73        ;Is it an 'I'
  160.     jz  increase_magnitude
  161.     cmp al,105        ;or an 'i'
  162.     jz  increase_magnitude
  163.  
  164.     cmp al,68        ;Is it a 'D'
  165.     jz decrease_magnitude
  166.     cmp al,100        ;or a 'd'
  167.     jz decrease_magnitude
  168.  
  169.     cmp al,43        ;is it a plus sign?
  170.     jz increase_delay
  171.     
  172.     cmp al,45        ;or a minus sign
  173.     jz decrease_delay
  174.  
  175.     jmp is_key_waiting    ;then it wasn't a valid key
  176.  
  177. increase_magnitude:
  178.  
  179.     mov ax,magnitude    ;double it
  180.     cmp ax,32768        ;if more than 32767, ignore
  181.     jb do_inc
  182.     jmp print_magnitude
  183.  
  184. do_inc:    
  185.     shl ax,1
  186.     mov magnitude,ax
  187.     jmp print_magnitude
  188.  
  189. decrease_magnitude:
  190.  
  191.     mov ax,magnitude    ;halve it
  192.     cmp ax,1        ;if one or less, ignore it
  193.     ja do_dec
  194.     jmp print_magnitude 
  195.  
  196. do_dec:
  197.  
  198.     shr ax,1
  199.     mov magnitude,ax
  200.     jmp print_magnitude
  201.  
  202. increase_delay:
  203.  
  204.     mov cx,magnitude
  205.     add delay,cx
  206.     jmp print_delay
  207.  
  208. decrease_delay:
  209.  
  210.     mov cx,magnitude
  211.     sub delay,cx
  212.     jmp print_delay
  213.     
  214.  
  215. extended_code:
  216.  
  217.     mov ah,8        ;go get second part of key
  218.     int 21h
  219.     cmp al,72        ;is it an up arrow?
  220.     jz  decrease_tone
  221.     cmp al,80        ;or maybe a down arrow
  222.     jz  increase_tone
  223.     cmp al,77        ;is it a right arrow?
  224.     jz  increase_duration
  225.     cmp al,75        ;how about a left arrow?
  226.     jz  decrease_duration
  227.  
  228.     jmp is_key_waiting    ;wrong key pressed
  229.  
  230. increase_tone:
  231.  
  232.     inc tone
  233.     jmp check_tone
  234.     
  235. decrease_tone:
  236.  
  237.     dec tone
  238.  
  239. check_tone:
  240.  
  241.     cmp tone,1
  242.     jb make_tone_127
  243.     cmp tone,127
  244.     ja make_tone_1
  245.     jmp print_tone
  246.  
  247. make_tone_127:
  248.  
  249.     mov tone,127
  250.     jmp print_tone
  251.  
  252. make_tone_1:
  253.  
  254.     mov tone,1
  255.     jmp print_tone
  256.  
  257. increase_duration:
  258.  
  259.     mov cx,magnitude
  260.     add duration,cx
  261.     jmp print_duration
  262.  
  263. decrease_duration:
  264.  
  265.     mov cx,magnitude
  266.     sub duration,cx
  267.     jmp print_duration
  268.  
  269. print_tone:
  270.  
  271.     mov dl,7        ;position the cursor at column 7
  272.     call cursor
  273.     mov al,tone        ;set up the tone
  274.     cbw            ;make it a word
  275.     jmp print_value
  276.  
  277. print_duration:
  278.  
  279.     mov dl,24
  280.     call cursor
  281.     mov ax,duration
  282.     jmp print_value
  283.  
  284. print_delay:
  285.  
  286.     mov dl,38
  287.     call cursor
  288.     mov ax,delay
  289.     jmp print_value
  290.  
  291. print_magnitude:
  292.  
  293.     mov dl,56
  294.     call cursor
  295.     mov ax,magnitude
  296.  
  297. print_value:
  298.  
  299.     cmp ax,9999        ;is it more than 9,999?
  300.     ja  tenthousand        ;if so, go print it
  301.     call print_zero         ;otherwise, print a zero
  302.     jmp thousand
  303.  
  304. tenthousand:
  305.  
  306.     mov cx,10000
  307.     call print_a_character
  308.     
  309. thousand:            ;this just repeats what we did above
  310.  
  311.     cmp ax,999
  312.     ja  do_thousand
  313.     call print_zero
  314.     jmp hundred
  315.  
  316. do_thousand:
  317.  
  318.     mov cx,1000
  319.     call print_a_character
  320.  
  321. hundred:
  322.  
  323.     cmp ax,99
  324.     ja  do_hundred
  325.     call print_zero
  326.     jmp ten
  327.  
  328. do_hundred:
  329.  
  330.     mov cx,100
  331.     call print_a_character
  332.  
  333. ten:
  334.  
  335.     cmp ax,9
  336.     ja  do_ten
  337.     call print_zero
  338.     jmp zero
  339.  
  340. do_ten:
  341.  
  342.     mov cx,10
  343.     call print_a_character
  344.  
  345. zero:
  346.  
  347.     add ax,30h        ;convert digit to ascii and print
  348.     mov dl,al
  349.     mov ah,2
  350.     int 21h
  351.  
  352. do_it:
  353.  
  354.     call speaker        ;make the noise
  355.     call do_delay        ;wait around for the delay
  356.     jmp is_key_waiting
  357.  
  358. main        endp
  359. soundseg    ends
  360. end        start
  361.